package edu.pku.sei.modeler.uml.commands.umlclass;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.uml.Dependencies.Realization;
import edu.pku.sei.modeler.model.uml.Kernel.Classifier;
import edu.pku.sei.modeler.uml.commands.ConnectionModelDeleteCommand;

public class UMLRealizationDeleteCommand extends ConnectionModelDeleteCommand {

	public UMLRealizationDeleteCommand(MetaModelElement connectionModel,
			MetaModelElement sourceModel, MetaModelElement targetModel) {
		super(connectionModel, sourceModel, targetModel);
	}

	@Override
	public boolean canExecute() {
		if (this.sourceModel instanceof Classifier
				&& this.targetModel instanceof Classifier) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public void execute() {
		Realization realization = (Realization) this.connectionModel;
		realization.getSupplierDependency().remove(this.targetModel);
		realization.getClientDependency().remove(this.sourceModel);
		Classifier sourceModelElement = (Classifier) this.sourceModel;
		sourceModelElement.getSupplierDependency().remove(realization);
	}

	@Override
	public void undo() {
		Realization realization = (Realization) this.connectionModel;
		realization.getSupplierDependency().add(this.targetModel);
		realization.getClientDependency().add(this.sourceModel);
		Classifier sourceModelElement = (Classifier) this.sourceModel;
		sourceModelElement.getSupplierDependency().add(realization);
	}

}
